package com.game.simplegame.creature;

import com.game.simplegame.world.World;

/**
 * Created by Administrator on 2017-04-18.
 */
public abstract class MoveStatus implements ICreatureStatus {

    int destX;
    int destY;
    public MoveStatus(int x,int y){
        destX = x;
        destY = y;
    }

    @Override
    public void update(long dtSec, Creature creature, World world) {
        int x = creature.getX();
        int y = creature.getY();
        System.out.println("current "+x+","+y+"moving to " + destX + "," + destY);
        if(x>destX){
            x-=2;
            if(x<destX)x=destX;
        }
        else{
            x+=2;
            if(x>destX)x=destX;
        }
        if(y>destY){
            y-=2;
            if(y<destY)y=destY;
        }
        else{
            y+=2;
            if(y>destY)y=destY;
        }
        creature.moveTo(x,y);
        creature.addEnergy(creature.getMoveEnergyCost());
        if(x==destX&&y==destY){
            onDestination(creature,world);
        }
    }

    @Override
    public void onDisActive(Creature creature, World world) {

    }

    @Override
    public void onActive(Creature creature, World world) {

    }

    protected abstract void onDestination(Creature creature, World world);
}
